package org.riahispano.twitterds.services.impl;

import org.apache.log4j.Logger;
import org.riahispano.twitterds.exception.TwitterDSException;
import org.riahispano.twitterds.services.TwitterFollowersService;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import twitter4j.Paging;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;

import java.util.List;

/**
 * @author: ecamacho
 * riahispano 2010
 */
@Service("twitterFollowersService")
@RemotingDestination
public class TwitterFollowersServiceImpl implements TwitterFollowersService {

    private static final Logger logger = Logger.getLogger( TwitterFollowersServiceImpl.class );

    @RemotingInclude
    public List<User> getFollowers(String user, String password, int page) {
        Twitter twitter 		= new Twitter( user, password );
		List<User> followers	= null;
		try {
			Paging paging		= new Paging( page );
			followers 			= twitter.getFollowersStatuses( paging );
		} catch (TwitterException e) {
			logger.error( "[Error while getting followers]", e);
			throw new TwitterDSException( "Error while getting followers", e );
		}
		return followers;  
    }
}
